package com.tools.cleanmaster.utils;

import java.math.BigInteger;
import java.security.MessageDigest;

public class CodecUtils {
    private static final String TAG = "CodecUtils";

    /**
     * @return May be null
     */
    public static String getMD5Checksum(byte[] data) {
        return getMD5Checksum(data, Character.MAX_RADIX);
    }

    /**
     * @return May be null
     */
    public static String getMD5Checksum(byte[] data, int radix) {
        String result = null;

        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(data);
            BigInteger big = new BigInteger(md5.digest()).abs();
            return big.toString(radix);  // radix: 36
        } catch (Exception e) {
            if (FeatureConfig.DEBUG_LOG) {
                LogHelper.e(TAG, "Should never happen! Exception: " + e);
            }
        }

        return result;
    }
}
